<?php

/**
 * 
 *
 * @version $Id: class_kat.inc.php,v 1.14 2005/01/18 17:41:16 phppc Exp $
 * @copyright 2003 
 **/


/**
 * kat
 * 
 * @package 
 * @author Armin
 * @copyright Copyright (c) 2004
 * @version $Id: class_kat.inc.php,v 1.14 2005/01/18 17:41:16 phppc Exp $
 * @access public
 **/
class kat extends functions {
	var $kat_ids = array();
	var $kat_all_ids = array();
	var $n_tpl_kats = "";
	var $ids_array = array();
	var $n_tpl_kats_input = "";
	var $anzahl_kats = 0;
	var $tiefe = -1;
	var $db_kat = array();
	var $katname = array();
	var $katid = array();
	var $i = 0;
	var $set_first = 0;
	var $value = "";
	var $checked = array();
	/**
	 * kat::kat_set_values()
	 * 
	 * @return 
	 **/
	function kat_set_values () {
		$erg = $this->db_abfrage_q("SELECT * FROM ".$this->config["db_table_kat"]." ORDER by kat_id ASC");
		$anzahl_kats = 0;
		while($db_kat_array = $this->db_abfrage_fetch($erg)){
			$id = $db_kat_array['id'];
			$kat_id = $db_kat_array['kat_id'];
			if(!isset($this->kat_ids["$kat_id"])) $this->kat_ids["$kat_id"] = array();
			$this->db_kat[$db_kat_array['id']] = $db_kat_array;
			array_push($this->kat_ids["$kat_id"],$id);
			array_push($this->kat_all_ids,$id);
			$this->anzahl_kats++;
		} // while
	}
	/**
	 * kat::kat_rek()
	 * 
	 * @param $kat_id
	 * @param string $mode
	 * @param integer $mark
	 * @param integer $dont_show
	 * @param integer $set_first
	 * @param string $form_var
	 * @param integer $size
	 * @param string $cat_first_lang
	 * @return 
	 **/
	function kat_rek($kat_id,$mode = "",$mark = 0,$dont_show = -1,$set_first = 0,$form_var = "kat_id",$size = 1,$cat_first_lang = ""){
		$this->checked[0] = "";
		$this->checked[$mark] = "selected=\"selected\" ";
		if ($mode == "input" AND $set_first == 1) {
			$this->tpl_load("kat_input_first","kat/");
			$this->tpl_replace_vars(array("cat_first_lang" => $cat_first_lang,"checked" => $this->checked[0]));
			$this->n_tpl_kats_input = $this->tpl_output();
			$set_first = 0;
		}
		if(isset($this->kat_ids["$kat_id"])) {
			foreach ($this->kat_ids["$kat_id"] as $ukat_id) {
				if(!isset($this->checked[$ukat_id])) $this->checked[$ukat_id] = "";
				$ukat_name = $this->db_kat[$ukat_id]["name"];
				$this->tiefe++;
				if ($ukat_id != $dont_show) {
				    $einrueckung = "";
					for ($i = 0;$i < $this->tiefe;$i++) {
						$einrueckung .= ">>";
					}
					if ($mode == "input") {
						$this->tpl_load("kat_input_one","kat/");
						$this->tpl_replace_vars(array("checked" => $this->checked[$ukat_id],"ukat_id" => $ukat_id,"einrueckung" => $einrueckung,"ukat_name" => $ukat_name));
						$this->n_tpl_kats_input .= $this->tpl_output();
					}
					elseif ($mode == "ids") array_push ($this->ids_array,"$ukat_id");
					else {
						include $this->config["a_pfad"].$this->config["sub_dir_comp"] . $mode . ".inc.php";
					}
				$this->kat_rek($ukat_id,$mode,$mark,$dont_show,$set_first,$form_var,$size);
				}
				$this->tiefe--;
	    	} // while  	
		}else {
			if($mode == "input") $this->n_tpl_kats = "<select name=\"$form_var\" size=\"$size\">".$this->n_tpl_kats_input."</select>";
			if($mode == "ids") {
				$this->value = $this->ids_array;
			}
			else $this->value = $this->n_tpl_kats;
		}
		
	}
	/**
	 * kat::kat_rueck()
	 * 
	 * @param $kat_id
	 * @return 
	 **/
	function kat_rueck ($kat_id) {
		if (count($this->katid) == 0) {
			$this->katid[1] = $kat_id;
			$this->i = 2;
		}
		$okat_id = $this->db_kat[$kat_id]["kat_id"];
		if ($okat_id >= 1) {
		    $this->katname[$this->i] = $this->db_kat["$okat_id"]["name"];
			$this->katid[$this->i] = $okat_id;
			$this->i++;
			$this->kat_rueck($okat_id);
		}else {
			krsort ($this->katid);
			reset ($this->katid);
			$tiefe = 0;
			foreach ($this->katid AS $zahl => $kid) {
				unset ($einrueckung);
				for ($b = 0;$b < $tiefe;$b++) {
					$this->tpl_load("news_kat_einrueckung");
					$einrueckung .= $this->tpl_output();
				}
				$this->module_new_value["action"] = "show";
				$kat_link = $this->fun_make_link("","kat_id=".$kid."");
				$this->tpl_load("news_kat_one");
				$this->tpl_replace_vars(array("einrueckung" => $einrueckung,"kat_link" => $kat_link,"kname" => $this->db_kat[$kid]["name"]));
				$news_kats .= $this->tpl_output();
				$tiefe++;
			}
			$this->value = $news_kats;
		}
	}	
	/**
	 * kat::kat_return_value()
	 * 
	 * @return 
	 **/
	function kat_return_value(){
		$return = $this->value;
		$this->value = "";
		$this->ids_array = array();
		$this->n_tpl_kats = "";
		$this->n_tpl_kats_input = "";
		$this->tiefe = -1;
		$this->katname = array();
		$this->katid = array();
		$this->checked = array();
		return $return;
	}

}

?>